package cn.wolfcode.qo;

import lombok.Getter;


import java.util.List;
@Getter//给EL表达式用
public class PageResult<T> {
    private int currentPage;//请求传过来
    private int pageSize;   //请求传过来
    private int totalCount; //数据库中查询出来的
    private List<T> data;   //数据库中查询出来的

    private int totalPage;  //后面计算出来的
    private int prevPage;    //后面计算出来的
    private int nextPage;   //后面计算出来的

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        if (this.totalCount <= this.pageSize) { //数据只够一页
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
            return;
        }

        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
    }
}
